#pragma once

#include <cv.h>
#include <list>

class LPR {
public:
	LPR (const IplImage* plate) :m_plate(cvCloneImage(plate)), m_gray(0), m_threshold(100), m_result(0) { 
		compute(); 
	};

	unsigned long result (void) const;

	~LPR(void) { cvReleaseImage(&m_plate); cvReleaseImage(&m_gray); };
protected:
	void compute (void);
	void segmentify (void);
	void binarify (void);
	void calc_threshold (void);
	void add_object (IplImage* img, int row, int col, int visitcolor);
	void recognize (void);
	void clean (void);

	// definitions:
	typedef std::pair<int, int> t_cord;
	typedef std::pair<t_cord, t_cord> t_rect;
	typedef std::list<t_rect> t_segmentlist;

	// members:
	t_segmentlist m_digits;							// image segments likely to hold the digits
	unsigned long m_result;							// the result
	IplImage* m_plate;								// saving the original image
	IplImage* m_gray;								// grayscale image
	unsigned int m_threshold;						// threshold for the segmentation
	static const int ms_true = 255;					// places of interest in the image (digit areas etc)
	static const int ms_false = 0;					// other places of the image
	static const double ms_minDigitPercent;	// for eliminating segments unlikely to be digits
	static const double ms_maxDigitPercent;	// for eliminating segments unlikely to be digits
	static const double ms_yellowPercentage;	// for the binarify (histogram) [0.33 according to the article]
};
